package com.hollycrm.unicom.sheet.business.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.hollycrm.springframework.util.StringUtils;
import com.hollycrm.springframework.web.struts.DispatchActionSupport;
import com.hollycrm.unicom.lockservice.LockManager;
import com.hollycrm.unicom.security.AuthToken;
import com.hollycrm.unicom.sheet.BeanResource;

/**
 * UnlockAction
 *
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */
public class UnlockAction extends DispatchActionSupport {
    /**
     * execDefault
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execDefault(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        String lockID = request.getParameter("lockID");
        LockManager lockManager = (LockManager) getBean(BeanResource.LOCK_MANAGER);
        AuthToken authToken = (AuthToken) request.getSession().getAttribute(AuthToken.BEAN_ID);
        if (StringUtils.isNotEmpty(lockID)) {
            lockManager.unlock(lockID, authToken.getUserCode());
        }
        return null;
    }
}
